package dmitrygusev.ratings.templates;

import org.apache.log4j.Logger;

import dmitrygusev.io.IOUtils;
import dmitrygusev.nanoxml.lite.XMLElement;

public class TemplateLoader {
	public static final Logger logger = Logger.getLogger(TemplateLoader.class);
	
	public static XMLElement loadTemplate(String location, String encoding) throws Error {
		XMLElement queryFormXml = new XMLElement();
		
		try {
			String template = IOUtils.readToEnd(
					TemplateLoader.class.getResourceAsStream(location), encoding);
			
			queryFormXml.parseString(template);
		} catch (Exception e) {
			logger.fatal("Can't load template from " + location + ": " + e);
			throw new Error(e);
		}
		return queryFormXml;
	}
	
}
